package com.project.taglib.function;

import java.util.List;

import com.project.bean.Features;
import com.project.bean.FinalProject;
import com.project.bean.Function;
import com.project.bean.Role;
import com.project.bean.User;
import com.project.bo.FeaturesBO;
import com.project.bo.RoleBO;
import com.project.bo.UserBO;

public class Functions {

	public static User getUser(User user) {
		UserBO userBO = UserBO.getInstance();
		return userBO.getUserById(user);
	}
	
	public static List<Role> getRoles() {
		RoleBO roleBO = RoleBO.getInstance();
		return roleBO.getRoles();
	}
	
	public static List<Features> getFeatures() {
		FeaturesBO featuresBO = FeaturesBO.getInstance();
		return featuresBO.getFeatures();
	}
	
	public static Features getFunctionsFromFeature(String url) {
		Features feature = null;
		for(Features features : FinalProject.getFeaturesMAP().getFeatures()) {
			if (features.getFeatureLink().equals(url)) {
				feature =  features;
				break;
			}
		}
		return feature;
	}
	
	public static Boolean containsFeature(List<Features> list, String feature) {
		Boolean result = Boolean.FALSE;
		if (list != null) {
			for(Features f : list) {
				if (f.getFeatureLink().equals(feature)) {
					result = Boolean.TRUE;
					break;
				}
			}
		}
		return result;
	}
	
	public static Boolean containsFunction(List<Function> list, String function) {
		Boolean result = Boolean.FALSE;
		if (list != null) {
			for(Function f : list) {
				if (f.getName().equalsIgnoreCase(function)) {
					result = Boolean.TRUE;
					break;
				}
			}
		}
		return result;
	}
	
	public static List<User> getUsers() {
		UserBO userBO = UserBO.getInstance();
		return userBO.getAllUsers();
	}
	
	public static String camuflatePass(String pass) {
		String result = "";
		for(int i = 0; i < pass.length();i++) {
			result += "*";
		}
		return result;
	}
	
}
